﻿using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Linq;
using System.Web;
using BookExchange.ODataService;

namespace BookExchange.Business
{
    public class MemberBusiness : BaseBusiness<Member>
    {


        public void UpdateMember(Member member)
        {
            this.DB.UpdateObject(member);
            this.DB.SaveChanges();

        }

        public Member GetMemberByEmail(string email)
        {
            return DB.Members.Where(m => m.Email == email).FirstOrDefault();
        }


        public Member GetMemberByCode(int memberCode)
        {
            return DB.Members.Where(m => m.MemberCode == memberCode).FirstOrDefault();                
        }

        public Member GetMember(string email, string password, bool isLock=false)
        {
            return DB.Members
                .Where(m => m.Email == email && m.Password == password && m.Lock == isLock)
                .FirstOrDefault();
        }


        #region Minh - 8.10.13
        public Member GetMemberByUsernameAndEmail(string name, string email)
        {
            return DB.Members.Where(q => q.DisplayName.Equals(name) && q.Email.Equals(email)).FirstOrDefault();
        }
        #endregion


        public override void Insert(Member obj)
        {
            DB.AddToMembers(obj);
            DB.SaveChanges();
        }

        public override void Update(Member obj)
        {
            DB.UpdateObject(obj);
            DB.SaveChanges();
        }

        public override void Delete(Member obj)
        {
            DB.DeleteObject(obj);
            DB.SaveChanges();
        }
    }
}